package cn.maihe.elg.operation.centers.guogu.handler.service;

import cn.maihe.elg.operation.centers.guogu.config.GuoGuCenterInfosConfig;
import cn.maihe.elg.operation.centers.guogu.dto.GuoGuBaseRespDTO;
import cn.maihe.elg.operation.centers.guogu.dto.handler.req.GuoGuProjectAbnormalApplyReq;
import cn.maihe.elg.operation.centers.guogu.handler.GuoGuCenterTradeService;
import cn.maihe.elg.operation.centers.supports.CenterTradeContext;
import cn.maihe.elg.operation.centers.supports.annotation.CenterTradeService;
import cn.maihe.elg.operation.model.enums.CenterNoEnum;
import cn.maihe.elg.operation.model.enums.CenterProviderEnum;
import cn.maihe.elg.operation.model.enums.TradeType;
import cn.maihe.elg.operation.service.business.ProjectInfoService;
import cn.maihe.elg.operation.service.invoice.InvoiceInfoService;
import cn.maihe.elg.operation.service.order.AcceptOrderInfoService;
import cn.maihe.elg.operation.service.order.ApplyOrderInfoService;
import cn.maihe.elg.operation.service.order.GuaranteeAttachmentInfoService;
import cn.maihe.elg.operation.supports.system.ElgResourceService;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * @Description 项目延期推送
 * @Author SSX
 * @Date 2025/03/18
 */
@CenterTradeService(
        provider = CenterProviderEnum.GUOGU,
        centerNo = CenterNoEnum.GUOGU,
        tradeType = TradeType.project_abnormal_apply,
        reqClass = GuoGuProjectAbnormalApplyReq.class,
        respClass = GuoGuBaseRespDTO.class
)
@Slf4j
public class GuoGuProjectAbnormalApplyService extends GuoGuCenterTradeService<GuoGuProjectAbnormalApplyReq, GuoGuBaseRespDTO> {
    public GuoGuProjectAbnormalApplyService(GuoGuCenterInfosConfig centerInfosConfig) {
        super(centerInfosConfig);
    }

    @Resource
    private AcceptOrderInfoService acceptOrderInfoService;
    @Resource
    private ElgResourceService elgResourceService;
    @Resource
    private GuaranteeAttachmentInfoService guaranteeAttachmentInfoService;
    @Resource
    private ProjectInfoService projectInfoService;
    @Resource
    private InvoiceInfoService invoiceInfoService;
    @Resource
    private ApplyOrderInfoService applyOrderInfoService;

    @Override
    protected void verifyParam(CenterTradeContext<GuoGuProjectAbnormalApplyReq, GuoGuBaseRespDTO> context) {
        super.verifyParam(context);
//        GuoGuProjectAbnormalApplyReq req = context.getReq();
//        String orderNo = req.getApplyno();
//        boolean exists = acceptOrderInfoService.existsCenterOrderId(context.getCenterId(), orderNo);
//        Assert.isTrue(!exists, () -> "中心订单编号已存在");
    }

    @Override
    public GuoGuBaseRespDTO processService(CenterTradeContext<GuoGuProjectAbnormalApplyReq, GuoGuBaseRespDTO> context) {
        return GuoGuBaseRespDTO.error("暂不支持项目延期");
     /*   GuoGuProjectAbnormalApplyReq req = context.getReq();
        List<String> insureOrderNos = req.getInsureOrderNos();
        if(Collections.isEmpty(insureOrderNos) || StringUtils.isBlank(req.getExtensionDays())){
            log.error("项目延期推送失败 insureOrderNos:{}，{},", insureOrderNos, req.getExtensionDays());
            return GuoGuBaseRespDTO.error("参数异常");
        }

        for (int i = 0; i < insureOrderNos.size(); i++) {
            AcceptOrderInfoDO orderInfoDO = acceptOrderInfoService.getByGuaranteeNo(context.getCenterId(), context.getOrgId(), insureOrderNos.get(i));
            if (orderInfoDO.getStatus() == AcceptOrderStatus.FINISH.getStatus()) {
                continue;
            }
            if (orderInfoDO.getStatus() == AcceptOrderStatus.CANCEL.getStatus()) {
                continue;
            }
            if (orderInfoDO.getStatus() != AcceptOrderStatus.HAS_OUT_GUARANTEE.getStatus()) {
                continue;
            }
            // 保函还原
            InvoiceInfoDO invoiceInfoDO = invoiceInfoService.selectById(orderInfoDO.getInvoiceId());
            try {
                applyOrderInfoService.applyGuarantee(orderInfoDO, invoiceInfoDO, null,false);
            }catch (Exception e){
                log.error("项目延期推送失败 insureOrderNo:{}，{},", insureOrderNos.get(i), e.getMessage(), e);
            }
        }

        return GuoGuBaseRespDTO.success("处理完毕");*/
    }


}
